package com.wondream.myframework.app.common.util;


import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.InputStream;

/**
 * 文件工具类 commons-io
 */
public class FileUtils {

    public static void copyToFile(String fromFileName, String toFileName) throws Exception {
        // 1.获取输入流
        ClassPathResource classPathResource = new ClassPathResource(fromFileName);
        InputStream inputStream = classPathResource.getInputStream();

        // 2.生成目标文件
        File toFile = new File(String.format("./tmp/%s", toFileName));

        // 3.拷贝内容到文件
        try {
            org.apache.commons.io.FileUtils.copyToFile(inputStream, toFile);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }

    public static void main(String[] args) throws Exception {
        FileUtils.copyToFile("application.properties", "application.properties");
    }
}
